package cb.com.etcdemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cb.com.etcdemo.bean.DeviceState;
import cb.com.etcdemo.bean.DeviceStateOnLine;
import cb.com.etcdemohgz.R;

/**
 * 说明：适配器
 *
 * @author 崔斌
 */
public class OnlineAdapter extends BaseAdapter {
    Context context;

    public List<DeviceStateOnLine.ListBean> getInfos() {
        return infos;
    }

    public void setInfos(List<DeviceStateOnLine.ListBean> infos) {
        this.infos = infos;
    }

    List<DeviceStateOnLine.ListBean> infos;

    public OnlineAdapter(Context context, List<DeviceStateOnLine.ListBean> infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return infos.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return infos.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
        ViewHolder holder;
        if (arg1 == null) {
            holder = new ViewHolder();
            arg1 = LayoutInflater.from(context).inflate(
                    R.layout.listview_item_complete, arg2, false);
            holder.tv_stationName = (TextView) arg1
                    .findViewById(R.id.tv_stationName);
            holder.tv_deviceIp = (TextView) arg1
                    .findViewById(R.id.tv_deviceIp);
            holder.tv_currentVersion = (TextView) arg1
                    .findViewById(R.id.tv_currentVersion);
            holder.tv_offLineMinute = (TextView) arg1
                    .findViewById(R.id.tv_offLineMinute);
            holder.tv_Lanenumber = (TextView) arg1
                    .findViewById(R.id.tv_Lanenumber);
            holder.tv_4Gnumber = (TextView) arg1
                    .findViewById(R.id.tv_4Gnumber);
            holder.tv_paynet = (TextView) arg1
                    .findViewById(R.id.tv_paynet);
            holder.tv_sernet = (TextView) arg1
                    .findViewById(R.id.tv_sernet);
            holder.tv_sla = (TextView) arg1
                    .findViewById(R.id.tv_sla);
            holder.tv_ses = (TextView) arg1
                    .findViewById(R.id.tv_ses);
            holder.tv_veh = (TextView) arg1
                    .findViewById(R.id.tv_veh);

            arg1.setTag(holder);
        } else {
            holder = (ViewHolder) arg1.getTag();
        }
        try {
            final DeviceStateOnLine.ListBean info = infos.get(arg0);
             holder.tv_stationName.setText(info.getStationName()==null?"收费站名称：暂无":"收费站名称："+info.getStationName());
            holder.tv_deviceIp.setText(info.getDeviceIp()==null?"设备ID：暂无":"设备ID："+info.getDeviceId());
            holder.tv_currentVersion.setText(info.getCurrentVersion()==null?"当前版本：暂无":"当前版本："+info.getCurrentVersion());
            holder.tv_offLineMinute.setText(info.getOffLineMinute()==null?"离线时长(分)：暂无":"离线时长(分)："+info.getOffLineMinute());
            holder.tv_Lanenumber.setText(info.getVehicleNum()==null?"当前车道ID：暂无":"当前车道ID："+info.getVehicleNum());
            holder.tv_4Gnumber.setText(info.getFgBoxVersion()==null?"4G盒子版本：暂无":"4G盒子版本："+info.getFgBoxVersion());
            holder.tv_paynet.setText(info.getPaynet()==null?"支付网络状态：暂无":"支付网络状态："+info.getPaynet());
            holder.tv_sernet.setText(info.getSerial()==null?"通信串口状态：暂无":"通信串口状态："+info.getSerial());
            holder.tv_sla.setText(info.getSlavemac()==null?"从机通信状态：暂无":"从机通信状态："+info.getSlavemac());
            holder.tv_ses.setText(info.getSestatus()==null?"SE状态：暂无":"SE状态："+info.getSestatus());
            holder.tv_veh.setText(info.getVehicleNumOri()==null?"库存车道ID：暂无":"库存车道ID："+info.getVehicleNumOri());

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return arg1;
    }


    static class ViewHolder {
        TextView tv_stationName, tv_deviceIp,tv_veh,
                tv_currentVersion,tv_offLineMinute,tv_Lanenumber,tv_4Gnumber,tv_paynet,tv_sernet,tv_sla,tv_ses;
    }
}
